﻿#include "StatusLightWidget.h"

#include <QPainter>
#include <QBrush>

StatusLightWidget::StatusLightWidget(QWidget *parent, const QColor &color, quint32 size)
    : QWidget(parent)
    , size_(size)
    , color_(color)
{

}

void StatusLightWidget::setSize(quint32 size)
{
    if (size_ != size) {
        size_ = size;
        update();
    }
}

quint32 StatusLightWidget::getSize() const
{
    return size_;
}

void StatusLightWidget::setColor(const QColor& color)
{
    color_ = color;
    update();
}

QColor StatusLightWidget::getColor() const
{
    return color_;
}

void StatusLightWidget::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter painter(this);

    // 抗锯齿
    painter.setRenderHint(QPainter::Antialiasing);

    // 设置画笔为透明，确保没有边框
    painter.setPen(Qt::NoPen);

    // 绘制画刷颜色
    painter.setBrush(QBrush(color_));

    // 绘制圆形
    painter.drawEllipse(rect().center(), size_, size_);
}
